package com.hmy.cornpestdet.controller;

import com.hmy.cornpestdet.pojo.WarningSystem;
import com.hmy.cornpestdet.service.WarningSystemService;
import com.hmy.cornpestdet.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/warningSystem")
public class WarningSystemController {
    @Autowired
    WarningSystemService warningSystemService;

    @PostMapping("/addWarningSystem")
    public Result addWarningSystem(@RequestBody WarningSystem warningSystem) {
        return warningSystemService.addWarningSystem(warningSystem);
    }

    @GetMapping("/getWarningSystemByProvince")
    public Result getWarningSystemByProvince() {
        WarningSystem warningSystem = warningSystemService.getCurrentUserWarningSystem();
        if(warningSystem == null) {
            return Result.Error("未发布预警信息");
        }
        return Result.Success("查询预警信息成功", warningSystem);
    }

}
